package com.yinhe.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.system.domain.YhVacation;
import com.yinhe.system.service.IYhVacationService;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.common.core.page.TableDataInfo;

/**
 * 休假记录Controller
 * 
 * @author yinhe
 * @date 2022-09-04
 */
@RestController
@RequestMapping("/system/vacation")
public class YhVacationController extends BaseController
{
    @Autowired
    private IYhVacationService yhVacationService;

    /**
     * 查询休假记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:vacation:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhVacation yhVacation)
    {
        startPage();
        List<YhVacation> list = yhVacationService.selectYhVacationList(yhVacation);
        return getDataTable(list);
    }

    /**
     * 导出休假记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:vacation:export')")
    @Log(title = "休假记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhVacation yhVacation)
    {
        List<YhVacation> list = yhVacationService.selectYhVacationList(yhVacation);
        ExcelUtil<YhVacation> util = new ExcelUtil<YhVacation>(YhVacation.class);
        util.exportExcel(response, list, "休假记录数据");
    }

    /**
     * 获取休假记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:vacation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhVacationService.selectYhVacationById(id));
    }

    /**
     * 新增休假记录
     */
    @PreAuthorize("@ss.hasPermi('system:vacation:add')")
    @Log(title = "休假记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhVacation yhVacation)
    {
        return toAjax(yhVacationService.insertYhVacation(yhVacation));
    }

    /**
     * 修改休假记录
     */
    @PreAuthorize("@ss.hasPermi('system:vacation:edit')")
    @Log(title = "休假记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhVacation yhVacation)
    {
        return toAjax(yhVacationService.updateYhVacation(yhVacation));
    }

    /**
     * 删除休假记录
     */
    @PreAuthorize("@ss.hasPermi('system:vacation:remove')")
    @Log(title = "休假记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhVacationService.deleteYhVacationByIds(ids));
    }
}
